import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import * as path from 'path';
// https://vitejs.dev/config/
export default defineConfig({
    resolve: {
        //设置别名
        alias: {
            '@': path.resolve(__dirname, 'src'),
            "@assets": path.resolve(__dirname, "src/assets"),
            "@components": path.resolve(__dirname, "src/components"),
            "@common": path.resolve(__dirname, "src/common"),
            "@images": path.resolve(__dirname, "src/assets/images"),
            "@pages": path.resolve(__dirname, "src/pages"),
            "@store": path.resolve(__dirname, "src/store"),
            "@css": path.resolve(__dirname, "src/css"),
            "@home": path.resolve(__dirname, "src/home"),
        }
    },
  plugins: [
      vue(),
      AutoImport({
        resolvers: [ElementPlusResolver()],
      }),
      Components({
        resolvers: [ElementPlusResolver()],
      }),
  ],
    build: {
        outDir: "dist",
        // 9月更新
        assetsDir: "assets", //指定静态资源存放路径
        sourcemap: false, //是否构建source map 文件
        terserOptions: {
            // 生产环境移除console
            compress: {
                drop_console: true,
                drop_debugger: true,
            },
        },
    },
    server: {
        port: 3000, //启动端口
        // hmr: {
        //     host: '0.0.0.0',
        //     port: 3000
        // },
        cors:true,
        // 设置 https 代理
        proxy: {
            '/api': {
                target: 'http://29.23.29.230:31001',
                ws:false,
                changeOrigin: true,
                rewrite: (path: string) => path.replace(/^\/api/, '/api')
            },
            '/czpt':{
                target: 'https://piam-sit.cpic.com.cn',
                ws: false,
                changeOrigin: true,
                rewrite: (path: string) => path.replace(/^\/czpt/, '/czpt')
            }
        }
    }
})
